#include "xbox.hpp"
#include "fcntl.h"
xbox_input::xbox_input(std::string path)
{
	if (this->dev_open(path) == 0)
		std::cout << "successfully open device " << path << std::endl;
}

xbox_input::~xbox_input()
{
	close(this->fd);
}

int xbox_input::dev_open(std::string path)
{
	this->fd = open(path.c_str(), O_RDONLY);
	if (this->fd <= 0)
	{	
		std::cerr << "failed to open device " << path << std::endl;
		return this->fd;
	}
	return 0;
}

int xbox_input::read_event(js_event &event)
{
	if (this->fd < 0)
		return this->fd;
	return read(this->fd, &event, sizeof(event));
}







